function M = deseq(data,index1,index2,index3)
% deseq(index1,index2,index3)
% construct a matrix or 3-dimensional array from a sequencialized output
assert(nargin>2,'There must be at least 2 indies');
if (nargin == 3)
    M = zeros(index1,index2);
    for i1 = 1:index1
        for i2 = 1:index2
            M(i1,i2) = data((i1-1)*index2+i2);
        end
    end
elseif(nargin == 4)
    M = zeros(index1,index2,index3);
    for i1 = 1:index1
        for i2 = 1:index2
            for i3 = 1:index3
                M(i1,i2,i3) = data((i1-1)*(index2*index3)+(i2-1)*index3+i3);                
            end
        end
    end
end

